//
//  MXCollocaSingleItemTableViewCell.m
//  MXの衣柜
//
//  Created by 马霄 on 15/8/12.
//  Copyright (c) 2015年 霄 马. All rights reserved.
//

#import "MXCollocaSingleItemTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface MXCollocaSingleItemTableViewCell ()
@property (nonatomic, retain) UILabel *mainLabel;

@property (nonatomic, retain) UIImageView *iconImageView;

@property (nonatomic, retain) UILabel *styleLabel;

@property (nonatomic, retain) UILabel *titleLabel;

@property (nonatomic, retain) UILabel *priceLabel;

@property (nonatomic, retain) UILabel *oldPriceLabel;

@property (nonatomic, retain) UIImageView *buttonImageView;

@property (nonatomic, retain) UIView *line;
@end
@implementation MXCollocaSingleItemTableViewCell

- (void)dealloc
{
    [_singleItemModel release];
    [_line release];
    [_buttonImageView release];
    [_oldPriceLabel release];
    [_mainLabel release];
    [_iconImageView release];
    [_styleLabel release];
    [_titleLabel release];
    [_priceLabel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.mainLabel = [[[UILabel alloc] init] autorelease];
        self.mainLabel.text = @"";
        self.mainLabel.layer.borderWidth = 0.5;
        self.mainLabel.layer.borderColor = [UIColor grayColor].CGColor;
        [self.contentView addSubview:self.mainLabel];
        
        self.iconImageView = [[[UIImageView alloc] init] autorelease];
        [self.mainLabel addSubview:self.iconImageView];
        
        self.styleLabel = [[[UILabel alloc] init] autorelease];
        [self.styleLabel setTextColor:[UIColor blueColor]];
        self.styleLabel.font = [UIFont systemFontOfSize:16];
        [self.mainLabel addSubview:self.styleLabel];
        
        self.priceLabel = [[[UILabel alloc] init] autorelease];
        [self.priceLabel setTextColor:[UIColor redColor]];
        [self.mainLabel addSubview:self.priceLabel];
    
        self.titleLabel = [[[UILabel alloc] init] autorelease];
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        [self.mainLabel addSubview:self.titleLabel];
        
        self.oldPriceLabel = [[[UILabel alloc] init] autorelease];
        self.oldPriceLabel.text = @"";
        [self.oldPriceLabel setTextColor:[UIColor grayColor]];
        self.oldPriceLabel.font = [UIFont systemFontOfSize:16];
        [self.mainLabel addSubview:self.oldPriceLabel];
        
        self.buttonImageView = [[[UIImageView alloc] init] autorelease];
        self.buttonImageView.image = [UIImage imageNamed:@"forward"];
        [self.mainLabel addSubview:self.buttonImageView];
        
        self.line = [[[UIView alloc] init] autorelease];
        self.line.backgroundColor = [UIColor blackColor];
        [self.oldPriceLabel addSubview:self.line];
        
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat margin = 10;
    CGFloat contviewWIDTH = self.contentView.frame.size.width;
    CGFloat contviewHEIGHT = self.contentView.frame.size.height;
    CGFloat mainLabelX = WIDTHPRO * margin;
    CGFloat mainLabelY = HEIGHTPRO * margin;
    CGFloat mainLabelW = contviewWIDTH - WIDTHPRO * 2 * margin;
    CGFloat mainLabelH = contviewHEIGHT - HEIGHTPRO * 2 * margin;
    self.mainLabel.frame = CGRectMake(mainLabelX, mainLabelY, mainLabelW, mainLabelH);
    
    CGFloat iconImageViewX = margin / 2;
    CGFloat iconImageViewY = margin / 2;
    CGFloat iconImageViewH = mainLabelH - 2 * iconImageViewY;
    CGFloat iconImageViewW = iconImageViewH;
    self.iconImageView.frame = CGRectMake(iconImageViewX, iconImageViewY, iconImageViewW, iconImageViewH);
    
    
    CGFloat styleLabelX = iconImageViewW + iconImageViewX + margin;
    CGFloat styleLabelY = iconImageViewY + margin / 2;
    CGFloat styleLabelW = WIDTHPRO * 60;
    CGFloat styleLabelH = (iconImageViewH - margin)/ 2;
    self.styleLabel.frame = CGRectMake(styleLabelX, styleLabelY, styleLabelW, styleLabelH);
    
    CGFloat titleLabelX = styleLabelX + styleLabelW;
    CGFloat titleLabelY = styleLabelY;
    CGFloat titleLabelW = WIDTHPRO * 180;
    CGFloat titleLabelH = styleLabelH;
    self.titleLabel.frame = CGRectMake(titleLabelX, titleLabelY, titleLabelW, titleLabelH);
    
    CGFloat priceLabelX = styleLabelX;
    CGFloat priceLabelY = styleLabelY + styleLabelH + margin / 2;
    CGFloat priceLabelW = WIDTHPRO * 80;
    CGFloat priceLabelH = styleLabelH;
    self.priceLabel.frame = CGRectMake(priceLabelX, priceLabelY, priceLabelW, priceLabelH);
    
    CGFloat oldPriceLabelX = priceLabelW + priceLabelX + margin;
    CGFloat oldPriceLabelY = priceLabelY;
    CGFloat oldPriceLabelW = WIDTHPRO * 120;
    CGFloat oldPriceLabelH = priceLabelH;
    self.oldPriceLabel.frame = CGRectMake(oldPriceLabelX, oldPriceLabelY, oldPriceLabelW, oldPriceLabelH);
    
    CGFloat buttonImageViewX = mainLabelW - WIDTHPRO * 30;
    CGFloat buttonImageViewY = styleLabelY + styleLabelH / 2;
    CGFloat buttonImageViewW = WIDTHPRO * 30;
    CGFloat buttonImageViewH = buttonImageViewW;
    self.buttonImageView.frame = CGRectMake(buttonImageViewX, buttonImageViewY, buttonImageViewW, buttonImageViewH);
    
    self.line.frame = CGRectMake(0, oldPriceLabelH / 2, oldPriceLabelW - WIDTHPRO * 50, HEIGHTPRO * 1);
    
}

-(void)getSingleItemInfo:(MXCollocaSingleItemModel *)model
{
    if (_singleItemModel != model) {
        [_singleItemModel release];
        _singleItemModel = [model retain];
    }
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.pic_url] placeholderImage:[UIImage imageNamed:@"plaseholder"]];
    
    self.styleLabel.text = [NSString stringWithFormat:@"%@:", model.MXdescription];
    
    self.titleLabel.text = model.title;
    
    self.priceLabel.text = [NSString stringWithFormat:@"¥ %@", model.coupon_price];
    
    self.oldPriceLabel.text = [NSString stringWithFormat:@"¥ %@", model.price];
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
